package com.simon.customer.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.simon.customer.dao.IDao;
import com.simon.customer.dao.impl.Dao;
import com.simon.customer.entity.DishType;
import com.simon.customer.entity.Dishes;
import com.simon.customer.entity.MerchantView;
import com.simon.customer.service.IService;
import com.simon.customer.urlconn.URLConnect;

public class Service implements IService{
	private IDao dao=new Dao();
	@Override
	public List<String> RequestMId() {	
		URLConnect conn=new URLConnect();
		return conn.urlConnect();
	}

	@Override
	public List<Dishes> searchDishes(String m_id) {
		return dao.searchDishes(m_id);
	}

	@Override
	public MerchantView showMerchant(String m_id) {
		return dao.searchMerchant(m_id);
	}

	@Override
	public List<DishType> showDishType(List<String> mId) {
		List<DishType> list=new ArrayList<>();
//		List<DishType> allDishType=dao.searchAlldishType();
		List<DishType> type;
		for(String m:mId){
			if((type=dao.searchDishTypeByMId(m))!=null){
				for(DishType t:type){
					list.add(t);
				}
			}
		}
		return list;
	}

	@Override
	public List<MerchantView> showMerchantByType(String t_id,List<String> str) {
		List<MerchantView> merchant=new ArrayList<>();
		List<MerchantView> viewList=dao.searchMerchantByDishType(t_id);
		for(MerchantView view:viewList){
			if(str.contains(view.getMerchantId())){
				merchant.add(view);
			}
		}
		return merchant;
	}

	@Override
	public List<Dishes> searchDishesByType(String m_id,String type) {
		// TODO Auto-generated method stub
		return dao.searchDishesTypeName(m_id, type);
	}

	@Override
	public List<DishType> showDishTypeByMId(String mId) {	
		return dao.searchaDishTypeByMid(mId);
	}

	@Override
	public String showMerchantName(String mId) {
		// TODO Auto-generated method stub
		return dao.getMerchantName(mId);
	}

	@Override
	public List<String> MidNotEmpty(List<String> str) {
		List<String> mId=new ArrayList<>();
		for(String s:str){
			if(dao.searchMerchantInFood(s)){
				mId.add(s);
			}
		}
		return mId;
	}

}
